import 'package:flutter/material.dart';
import 'package:flutter_trip_demo/pages/home_page.dart';
import 'package:flutter_trip_demo/pages/mine_page.dart';
import 'package:flutter_trip_demo/pages/travel_photo_page.dart';
import 'package:flutter_trip_demo/pages/search_page.dart';



class IndexPages extends StatefulWidget {
  const IndexPages({Key? key}) : super(key: key);

  @override
  _IndexPagesState createState() => _IndexPagesState();
}

class _IndexPagesState extends State<IndexPages> {
  //BottomNavigationBarItem集合使用，创建底部导航栏
  final List<BottomNavigationBarItem> bottomTabs =[
    const BottomNavigationBarItem(icon: Icon(Icons.home),label: '首页'),
    const BottomNavigationBarItem(icon: Icon(Icons.search),label: '搜索'),
    const BottomNavigationBarItem(icon: Icon(Icons.enhance_photo_translate),label: '旅拍'),
    const BottomNavigationBarItem(icon: Icon(Icons.account_circle),label: '我的'),
  ];

  //获取底部导航需要切换的页面集合
  final List tabBodies = [
      const HomePage(),
      const SearchPage(hideLefts: true),
      const TravelPhotoPage(),
      const MinePage(),
  ];

  int newIndex = 0;
  var newPage;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color.fromRGBO(244, 245, 245, 1.0),
      bottomNavigationBar: BottomNavigationBar(
        selectedItemColor: Colors.blue,
        type: BottomNavigationBarType.fixed,
        currentIndex: newIndex,
        items: bottomTabs,
        onTap: (index){
          setState(() {
            newIndex = index;
            newPage = tabBodies[newIndex];
          });
        },
      ),
      body: IndexedStack(
        index: newIndex,
        children: const [
          HomePage(),
          SearchPage(hideLefts: true),
          TravelPhotoPage(),
          MinePage(),
        ],
      ),
    );
  }
}
